package core.view
{
	import flash.events.MouseEvent;
	
	import org.ais.event.TEvent;
	import org.ais.system.Ais;
	import org.aisy.display.USprite;
	import org.aisy.listoy.Listoy;
	import org.aisy.listoy.ListoyData;
	import org.aisy.listoy.ListoyEvent;

	public class DownLoadListView extends USprite
	{
		protected var _listoy:Listoy;
		
		public function DownLoadListView()
		{
			init();
		}
		
		protected function init():void
		{
			var arr:Array = Ais.IMain.Swf.get("UNETSTREAMY_IMOON", "swf").content.getNetStream().getByteArr();
			if (!arr || arr.length === 0) {
				clear();
				return;
			}
			
			var _seekPointArr:Array = Ais.IMain.Swf.get("UNETSTREAMY_IMOON", "swf").content.getNetStream().getSeekPointArr();
			var _iArr:Array = [];
			
			for (var i:* in _seekPointArr) {
				_iArr[_iArr.length] = [i];
			}
			
			_iArr.sortOn(1, Array.NUMERIC);
			
			_listoy = new Listoy();
			_listoy.setLayout(ListoyData.VERTICAL);
			_listoy.setPadding(19, 1);
			_listoy.setBackground(true);
			_listoy.setRowColumn(7, 2);
			_listoy.setItemRenderer(DownLoadItem);
			_listoy.setDataProvider(_iArr);
			_listoy.initializeView();
			
			addChild(_listoy);
			
			__addEvent();
			
			if (TEvent.trigger("UP_WINDOW_AIS", "SHOW", [this, "DOWNLOAD_LIST", 0]) === false) {
				clear();
			}
			_seekPointArr = null;
			_iArr = null;
			arr = null;
		}
		
		protected function __addEvent():void
		{
			_listoy.addEventListener(MouseEvent.MOUSE_WHEEL, __listoyHandler);
			
			TEvent.newTrigger("DOWNLOAD_LIST", __triggerHandler);
		}
		
		protected function __removeEvent():void
		{
			TEvent.clearTrigger("DOWNLOAD_LIST");
		}
		
		protected function __listoyHandler(e:MouseEvent):void
		{
			var t:String;
			if (e.delta > 0) {
				t = ListoyEvent.PREVIOUS;
			}
			else {
				t = ListoyEvent.NEXT;
			}
			TEvent.trigger(_listoy.NAME, t);
			t = null;
		}
		
		protected function __triggerHandler():void
		{
			
		}
		
		override public function get height():Number
		{
			return _listoy.getHeight();
		}
		
		override public function clear():void
		{
			__removeEvent();
			_listoy = null;
			super.clear();
			Ais.IMain.stage.focus = Ais.IMain.stage;
		}
		
	}
}